package unitTest;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class InsertMsgCode {


    private static final String VALUE = "SUCCESS=1000#成功\n" +
            "\n" +
            "BUSI_ERROR=1001#服务器开了下小差\n" +
            "\n" +
            "DESC_TOO_LARGE=1002#简介太长了\n" +
            "\n" +
            "EXIST_USERID=2001#userId已经存在\n" +
            "\n" +
            "NO_USER=2002#不存在的用户\n" +
            "\n" +
            "HEADER_NO_USER_ID=2003#Header中没有UserId\n" +
            "\n" +
            "EXIST_EMAIL=2004#已经注册的邮箱地址\n" +
            "\n" +
            "EMIAL_OR_PASSWORD_ERROR=2005#用户名或者密码错误\n" +
            "\n" +
            "CREATE_DIARY_FAILURE=3001#创建记本失败\n" +
            "\n" +
            "EXIST_DIARY_TITLE=3002#已经存在的记本名称\n" +
            "\n" +
            "NO_DIARY=3003#没有符合这个ID的记本\n" +
            "\n" +
            "UPDATE_DIARY_FAILURE=3004#更新日志失败\n" +
            "\n" +
            "KEEP_LEAST_ONE_DIARY=3005#至少保留一个记本\n" +
            "\n" +
            "CREATE_FRAGMENT_FAILURE=6001#创建片段失败\n" +
            "\n" +
            "NO_FRAGMENT=6002#没有符合这个ID的片段\n" +
            "\n" +
            "UPDATE_FRAGMENT_FAILURE=6003#更新片段失败\n" +
            "\n" +
            "CREATE_DIALYSIGN_FAILURE=7001#创建日笺失败\n" +
            "\n" +
            "UPDATE_DIALYSIGN_FAILURE=7002#更新日笺失败\n" +
            "\n" +
            "NO_DIALYSIGN=7003#没有这个日笺\n" +
            "\n" +
            "CREATE_TIME_MACHINE_FAILURE=8001#创建日笺失败\n" +
            "\n" +
            "ALREADY_LIKE=4001#已经Like过了\n" +
            "\n" +
            "ALREADY_UNLIKE=4002#已经取消Like过了\n" +
            "\n" +
            "NO_LIKE=4003#不存在的Like\n" +
            "\n" +
            "LIKE_CANCLE_ERROR=4004#取消Like失败\n" +
            "\n" +
            "ALREADY_FOLLOW=5001#已经follow过了\n" +
            "\n" +
            "ALREADY_UNFOLLOW=5002#已经取消follow过了\n" +
            "\n" +
            "FOLLOW_ERROR=5003#添加关注失败\n" +
            "\n" +
            "FOLLOW_CANCLE_ERROR=5004#取消关注失败\n" +
            "\n" +
            "NO_FOLLOW=5005#不存在的关注\n" +
            "\n" +
            "NO_FOLLOW_ANY=5006#没有关注任何人与记本\n" +
            "\n" +
            "FOLLOW_SELF=5007#不能关注自己\n" +
            "\n" +
            "FOLLOW_SELF_DIARY=5008#不需要关注自己的记本~\n" +
            "\n" +
            "USERID_NOT_MATCH=6000#非授权的更新操作\n" +
            "\n" +
            "ALREADY_HAS_PUSH=5501#已经添加过推送了\n" +
            "\n" +
            "ALREADY_NOT_PUSH=5502#已经取消推送过了\n" +
            "\n" +
            "ADD_PUSH_ERROR=5503#添加推送失败\n" +
            "\n" +
            "CANCLE_PUSH_ERROR=5504#取消推送失败\n" +
            "\n" +
            "NO_PUSH=5505#不存在的推送\n" +
            "\n" +
            "NOT_OWNER_COMMNET=6000#不属于你的评论\n" +
            "\n" +
            "ADD_COMMENT_ERROR=6001#评论失败\n" +
            "\n" +
            "SERVER_ERROR=5000#服务器内部异常\n" +
            "\n" +
            "NO_UA=5888#接口请求缺乏UA\n" +
            "\n";

    public static void main(String[] args) throws Exception{

        String[] strings = VALUE.split("\n");
        for (String str : strings){
            String[] split = str.split("=");
            if (split.length == 2){
                String[] strings1 = split[1].split("#");
                if (strings1.length == 2){
                    System.out.println(strings1[0]+"="+strings1[1]);
//                    String code = "7888";
//                    String msg = "sadsad";
                    RestTemplate restTemplate = new RestTemplate();
                    HttpHeaders headers = new HttpHeaders();
//                 MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
                    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
//                 headers.add("Accept", MediaType.APPLICATION_JSON.toString());
                    headers.add("Cookie","uuid=MTUwNzU0MDgxMjIxMVFuekM2TkljaTc=; UM_distinctid=15f006f612fb3d-06b3a0aa210da-31637c01-13c680-15f006f6130dd6; CNZZDATA1258389938=723507539-1507537796-%7C1507537796; token=M0U0RTAxMjE3RTFGQTM3RDBENkE3Njc0NzAwMzU4NkE=; cookieUserId=YWRtaW4=; cookieUserName=YWRtaW4=; cookieRemberPwd=WUVT; cookiePassword=38C97069F11ABCD00F6014D6FA5C69BE");
                    String params = "&id=&createTime=&status=0&sequence=0&errorCode=" + strings1[0] + "&errorMsg=" + URLEncoder.encode(strings1[1],"utf8") + "&projectId=ffff-1507535560192-10108153-0002&projectName=OneDay_API&logRemark=";
                    System.out.println("params:"+params);
                    HttpEntity<String> formEntity = new HttpEntity<>(params, headers);
                    String result = restTemplate.postForObject("http://localhost:9001/api/user/error/addOrUpdate.do", formEntity, String.class);
                    System.out.println("result:"+result);
                }
            }
        }


    }
}
